# frozen_string_literal: true

namespace '/member' do
  helpers ApiHelpers
  before do
    auth_gate
    inject_params
  end

  post '/list' do
    ap @json_params
    # puts env
    # puts env['HTTP_SECURE']
    current_page = @json_params[:current_page] || 1
    page_size = Config.current_page_size || 7
    {
      code: 'ok',
      payload: {
        total: Member.valid.count,
        page_size: page_size,
        objs: Member.valid.only(:mobile, :name, :created_at, :t_id)
                    .page(current_page).per(page_size)
      }
    }.to_json

    # Member.all.to_json
  end

  post '/delete' do
    puts @json_params
    puts @json_params[:t_id]
    Member.find(@json_params[:t_id]).soft_delete
  end
end
